unit JATUIF_Component_ColorBox;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, JATUIF_Component, JATUIF_Driver_Screen;

Type

    { TColorBox }

    TColorBox = class(TComponent)
      Protected
        Procedure _OnKeyPress(Key:Char); override;
        Procedure _OnMouseEnter; override;
        Procedure _OnMouseLeave; override;
        Procedure _OnClick; override;
        Procedure _OnLoseFocus; override;
        Procedure Draw; override;
      Private
        { Private Properties & Methods }
        Draws      : Integer;
        Back       : Byte;
        ColX, ColY : Byte;
      Public
        Constructor Create(Parent:TScreen; X1,Y1,X2,Y2:Integer; Background : Byte);
        Procedure New;
    end;

implementation

{ TColorBox }

constructor TColorBox.Create(Parent: TScreen; X1, Y1, X2, Y2: Integer; Background : Byte);
begin
     Draws:= 0;
     Back:= Background;
     inherited Create(Parent, X1, Y1, X2, Y2);
end;

procedure TColorBox.New;
begin
     ColX:= Self.GetX1+Random(Self.GetX2-Self.GetX1);
     ColY:= Self.GetY1+Random(Self.GetY2-Self.GetY1);
     Draw;
end;

procedure TColorBox.Draw;
Var
   i,n:integer;

begin
     Inc(Draws);
     If Draws > 35 then begin
        For i:=Self.GetX1 to Self.GetX2 do begin
            For n:=Self.GetY1 to Self.GetY2 do begin
                Screen.DrawCharXY(Self.GetTag,i,n,' ',Back,Back);
            end;
        end;
        Draws:=0;
     end;
     Screen.DrawCharXY(Self.GetTag,ColX,ColY,#7,Random(15),Back);
end;

{ Callback Events }

procedure TColorBox._OnKeyPress(Key: Char);
begin
     inherited _OnKeyPress(Key);
end;

procedure TColorBox._OnMouseEnter;
begin
     inherited _OnMouseEnter;
end;

procedure TColorBox._OnMouseLeave;
begin
     inherited _OnMouseLeave;
end;

procedure TColorBox._OnClick;
begin
     inherited _OnClick;
end;

procedure TColorBox._OnLoseFocus;
begin
     inherited _OnLoseFocus;
end;

end.

